package com.hopu.mybatis01.controler;

import com.hopu.mybatis01.mapper.UserMapper;
import com.hopu.mybatis01.pojo.User;
import com.hopu.mybatis01.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController//给当前类创建对象，把对象放入Spring容器中,将网页返回为数据
@RequestMapping("user")
public class UserControler {
    @Resource//给userMapper赋值
    private IUserService userService;
    
    @GetMapping//查找操作
    public List<User> getUser(String username,String password) {
        return userService.select(username,password);
    }
    @PostMapping//添加操作
    public void insertUser(@RequestBody User user) {
        userService.insert(user.getUsername(),user.getPassword());
    }
    @DeleteMapping
    public void deleteUser(@RequestBody User user) {
        userService.delete(user.getId());
    }
    @PutMapping
    public void updateUser(@RequestBody User user) {
        userService.update(user.getId(),user.getUsername(),user.getPassword());
    }

}
